package com.station.search.domain.converter;

import com.station.search.domain.StationInfo;
import com.station.search.domain.dto.StationInfoDTO;
import com.station.search.domain.vo.StationInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * @author: JT
 * @date: 2021/10/26
 * @Title:
 */
@Mapper
public interface StationInfoConverter {

    StationInfoConverter INSTANCE = Mappers.getMapper(StationInfoConverter.class);

    @Mapping(target="lonDegrees", expression = "java(com.station.search.common.util.MathUtils.lonlatChangeToDFM(stationInfoDto.getLon())[0])")
    @Mapping(target="lonMinute", expression = "java(com.station.search.common.util.MathUtils.lonlatChangeToDFM(stationInfoDto.getLon())[1])")
    @Mapping(target="lonSecond", expression = "java(com.station.search.common.util.MathUtils.lonlatChangeToDFM(stationInfoDto.getLon())[2])")
    @Mapping(target="latDegrees", expression = "java(com.station.search.common.util.MathUtils.lonlatChangeToDFM(stationInfoDto.getLat())[0])")
    @Mapping(target="latMinute", expression = "java(com.station.search.common.util.MathUtils.lonlatChangeToDFM(stationInfoDto.getLat())[1])")
    @Mapping(target="latSecond", expression = "java(com.station.search.common.util.MathUtils.lonlatChangeToDFM(stationInfoDto.getLat())[2])")
    StationInfo dtoToDo(StationInfoDTO stationInfoDto);

    StationInfo voToDo(StationInfoVO stationInfoVO);

    @Mapping(target="lon", expression = "java(com.station.search.common.util.MathUtils.keep8Decimal(stationInfo.getLonDegrees() + stationInfo.getLonMinute() / 60 + stationInfo.getLonSecond() / 60 / 60))")
    @Mapping(target = "lat", expression = "java(com.station.search.common.util.MathUtils.keep8Decimal(stationInfo.getLatDegrees() + stationInfo.getLatMinute() / 60 + stationInfo.getLatSecond() / 60 / 60))")
    StationInfoDTO doToDto(StationInfo stationInfo);
}
